<template>
  <div class="product-list">
    <div
      v-for="item in car_products"
      :key="item.id"
      class="product-item"
    >
      <dl>
        <dt>
          <checkbox :checked="item.is_active === '1'" @change="selected(item)" />
          <img :src="item.cover" />
        </dt>
        <dd>
          <div class="info">
            <h2>{{item.title}}</h2>
            <p>
              累计销售{{item.volume}}份
              <span>/</span>
              剩余库存{{item.count}}份
            </p>
          </div>
          <div class="bottom">
            <div>
              <span class="price">¥<b>{{item.price}}</b></span>
              <s class="oldPrice">¥{{item.oldPrice}}</s>
            </div>
            <number v-model="item.num" @change="(type) => change(item, type)" />
          </div>
        </dd>
      </dl>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'CarProductList',
  computed: {
    ...mapState('car', ['car_products'])
  },
  methods: {
    change (item, type) {
      this.$store.dispatch('car/update', {
        id: item.id,
        num: item.num
      })
    },
    selected (item) {
      this.$store.dispatch('car/update', {
        id: item.id,
        is_active: item.is_active === '1' ? '0' : '1'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.product-list {
  background: #fff;
  .product-item {
    @include wh(100%, auto);
    @include border1px(bottom, #E2E2E2);
    padding-left: 20px;
    dl {
      @include flex(row, initial, initial);
      dt {
        @include flex(row, center, center);
        // margin-right: 30px;
        img {
          @include wh(240px, 240px);
        }
      }
      dd {
        @include flex(column, space-between);
        padding: 30px;
        flex: 1;
        .info {
          h2 {
            @include ellipsisLn(2);
            font-size: 32px;
            max-height: 104px;
            line-height: 1.2;
          }
          p {
            font-size:24px;
            color: #999999;
            margin-top: 12px;
            span {
              margin: 0 10px;
            }
          }
        }
        .bottom {
          s {
            font-size: 24px;
            color: #999999;
          }
          span {
            font-size: 24px;
            color: #999999;
            b {
              font-size: 36px;
            }
            &.price {
              color: $base-color;
              margin-right: 10px;
            }
          }
        }
      }
    }
  }
}
</style>
